unit clsTipoLocalCobranca;

interface

uses Dm, dbtables, biblio;

type
  TTipoLocalCobranca = class(TObject)
  private
    Tipol_Codigo: string;
  public
    Tipol_Descricao: string;
    function Gravar(p_Tipol_Codigo: string): Byte;
    function Recuperar(p_Tipol_Codigo: string): Byte;
    function Excluir(p_Tipol_Codigo: string): Byte;
    procedure Consultar(var p_q: TQuery; p_nome: string);
  end;

implementation

function TTipoLocalCobranca.Gravar;
var
  tq: TQuery;
begin
  tq := Tquery.Create(DmInt);
  tq.databasename := dmint.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.params.clear;
  tq.sql.add('SELECT * FROM TipoLocalCobranca where Tipol_Codigo=:k_Tipol_Codigo');
  tq.parambyname('k_Tipol_Codigo').asstring := strzero(p_Tipol_Codigo, 2);
  tq.open;
  if tq.eof then begin
    tq.sql.clear;
    tq.params.clear;
    tq.sql.add('INSERT INTO TipoLocalCobranca VALUES(:k_Tipol_Codigo,:k_Tipol_Descricao)');
  end else begin
    tq.sql.clear;
    tq.params.clear;
    tq.sql.add('UPDATE TipoLocalCobranca SET Tipol_Descricao=:k_Tipol_Descricao WHERE Tipol_Codigo=:k_Tipol_Codigo');
  end;
  tq.parambyname('k_Tipol_Codigo').asstring := strzero(p_Tipol_Codigo, 2);
  tq.parambyname('k_Tipol_Descricao').asstring := Tipol_Descricao;
  tq.close;
  tq.execsql;
  result := 1;
  tq.close;
  tq.Free;
end;

function TTipoLocalCobranca.Recuperar;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := DmInt.Db.DatabaseName;
  tq.active := False;
  tq.sql.clear;
  tq.sql.add('SELECT * FROM TipoLocalCobranca where Tipol_Codigo=:k_Tipol_Codigo');
  tq.Params[0].asstring := strzero(p_Tipol_Codigo, 2);
  tq.open;
  Tipol_Codigo := p_Tipol_Codigo;
  if tq.eof then begin
    Tipol_Descricao := '';
    Result := 0;
  end else begin
    Tipol_Descricao := tq.fieldbyname('Tipol_Descricao').asstring;
    Result := 1;
  end;
  tq.Close;
  tq.Free;
end;

function TTipoLocalCobranca.Excluir;
var
  tq: TQuery;
begin
  tq := Tquery.Create(dmint);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tq.sql.Clear;
  tq.params.clear;
  tq.sql.add('DELETE FROM TipoLocalCobranca WHERE Tipol_Codigo=:k_Tipol_Codigo');
  tq.parambyname('k_Tipol_Codigo').asstring := strzero(p_Tipol_Codigo, 2);
  tq.execSQL;
  Result := 1;
  tq.close;
  tq.Free;
end;

procedure TTipoLocalCobranca.Consultar;
begin
  p_q.sql.Clear;
  p_q.Params.Clear;
  p_q.sql.add('Select * from TipoLocalCobranca where Tipol_Descricao>=:k_Tipol_Descricao order by Tipol_Descricao');
  p_q.parambyname('k_Tipol_Descricao').asstring := p_nome;
end;

end.
